<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>新增调价计划</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
   <%--  <link href="${ctx}/lib/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" /> --%>
   <style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>新增调价计划</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">药品调价</a></li>
            <li class="active"><a href="#">新增调价计划</a></li>
        </ol>
    </section>
    <section class="content">
    <form role="form" class="form-horizontal" action="priceChangeDetail.home" method="post">
       <div class=" box box-success ">
            <!-- form start -->
            
                <div class="box-body">
                    <div class="form-group  form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>计划名称：</label>
                        <div class="col-sm-4 text-left">
                            <input id="planName" class="form-control" placeholder="计划名称" type="text"  maxlength="170">
                        </div>
                    </div>
                    <div class="form-group  form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>计划类型：</label>
                        <div class="col-sm-4 text-left">
                        	<select class="form-control" id="executeType" name="executeType">
                        		<option value="1">手动执行</option>
                        		<option value="2">自动执行</option>
                        	</select>
                        </div>
                    </div>
                     <div class="form-group  form-group-xs" id="divAdd" style="display:none;" >
                        <label id="executeTimeLabel" class="col-sm-2 text-right" ><span class="required">*</span>执行时间：</label>
                        <div id="executeTimeDiv" class="col-sm-4 text-left input-group" >
                        	<input id="executeTime" class="form-control" type="text" readonly placeholder="执行时间精确到小时" data-provide="datepicker" data-date-fmt="yyyy年MM月dd日HH点"/>
                        	<div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                        </div>
                    </div>
                    <div class="form-group  form-group-xs">
                        <label class="col-sm-2 control-label"><span class="required">*</span>调价依据：</label>
                        <div class="col-sm-9  text-left">
                            <textarea id="planFrom" class="form-control" rows="3" placeholder="调价依据"  maxlength="170"></textarea>
                        </div>
                    </div>
                    <div class="form-group  form-group-xs">
                        <label class="col-sm-2 control-label">备&nbsp;&nbsp;注：</label>
                        <div class="col-sm-9  text-left">
                            <textarea class="form-control" id="remark" rows="3" placeholder="备注"  maxlength="340"></textarea>
                        </div>
                    </div>
                </div>
                
                <div class="box-footer text-center">
                    <button type="button" class="btn btn-primary btn-sm" onclick="save();">提 交</button>
                </div>
               </div>
            </form>
        
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
        $(document).ready(function() {
        	
        	$("#executeType").change(function() {
        		if ($(this).val() == "2") {
        			$("#divAdd").show();
        			$("#divAdd").show();
        		} else {
        			$("#divAdd").hide();
        			$("#divAdd").hide();
        		}
        	});
        	
        });
        function save(){
        	var planName=$.trim($('#planName').val());
        	var runType=$('#executeType').val(); ;
        	var runTime=$.trim($('#executeTime').val());
        	var planFrom=$.trim($('#planFrom').val());
        	var remark=$.trim($('#remark').val());
          	 var reg = new RegExp(regexEnum.num);
            if(planName==""){
            	$.HN.message.alert('请输入调价名称！', '提示信息', 'warn');
             	 return;
            }
          	if(planName.length>170){
          		$.HN.message.alert('调价名称长度不能超过170！', '提示信息', 'warn');
              	 return;
          	}
          	if(runType=="2"){
        		if(runTime==""){
        			$.HN.message.alert('请设置自动执行时间！', '提示信息', 'warn');
    	        	return;
        		}
        		runTime =runTime.replace(/年|月/g,"-").replace(/日/g," ").replace(/点/g,":");
            	var timestamp = Date.parse(runTime);
            	if(timestamp<new Date().getTime()){
            		$.alert("执行时间不能小于当前时间!","warn");
            		return;
            	}
        	}
        	 if(planFrom==""){
             	$.HN.message.alert('请输入调价依据！', '提示信息', 'warn');
              	 return;
             }
        	if(planFrom.length>170){
          		$.HN.message.alert('调价依据长度不能超过170！', '提示信息', 'warn');
              	 return;
          	}
        	$.HN.message.confirm('您确定要提交吗？', '', '').on(function (e) {
	        	if (e) {
		        	$.ajax({
			        	type:"POST",
			        	url:"submitPricePlanAdd.html",
			        	data:{
			        		"priceAdjPlanName":planName,
			        		"executeCat":runType,
			        		"executeDatetime":runTime,
			        		"remark":remark,
			        		"priceAdjAccord":planFrom
			        	},
			        	dataType:"json",
			        	success:function(result){
				        	if(result.success){
				        		top.$.alert('为您成功新增调价计划！','success');
				        		window.location.href = "toUnChangePlan.html";
				        	}else{
				        		$.HN.message.alert(result.msg, '提示信息', 'error');
				        	}
			        	},
						error:function() {
							top.window.document.location = "${ctx}/login.html";
						}
		        	});
	        	}
        	});
        }
        
        
    </script>
</body>
</html>
